<%@include file="/WEB-INF/pages/commons/commons.jsp" %>

<stripes:layout-render name="${_themePath}/basic-layout-without-navbar.jsp" _title="Edit Page">

    <stripes:layout-component name="_head">

        <c:out value="${_head}" escapeXml="false"/>

         <meta name="_uniquePageId_" content="_editPage_"/>

        <!-- Sam Skin CSS for TabView -->
        <link rel="stylesheet" type="text/css" href="<c:url value='/yui/build/tabview/assets/skins/sam/tabview.css'/>">

        <!-- JavaScript Dependencies for Tabview: -->
        <script type="text/javascript" src="<c:url value='/yui/build/yahoo-dom-event/yahoo-dom-event.js'/>"></script>
        <script type="text/javascript" src="<c:url value='/yui/build/element/element-min.js'/>"></script>

        <!-- OPTIONAL: Connection (required for dynamic loading of data) -->
        <script type="text/javascript" src="<c:url value='/yui/build/connection/connection-min.js'/>"></script>

        <!-- Source file for TabView -->
        <script type="text/javascript" src="<c:url value='/yui/build/tabview/tabview-min.js'/>"></script>

        <script type="text/javascript">
                // === spaceHeaderMenu
                YAHOO.util.Event.onContentReady("pageHeaderMenu", function() {
                    var manageHeaderMenu = new YAHOO.widget.Button("pageHeaderMenuButton",
                                            { type: "menu", menu: "pageHeaderMenuButtonSelect" });
                    //	"click" event listener for the second Button's Menu instance
                    var onMenuClick = function (p_sType, p_aArgs) {
                        var oEvent = p_aArgs[0];	//	DOM event
                        var oMenuItem = p_aArgs[1];	//	MenuItem instance that was the
                                                    //	target of the event
                        if (oMenuItem) {
                            if ('0' == oMenuItem.value) {   // Add Page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.AddPageActionBean" event="view">
                                        <stripes:param name="page" value=""/>
                                        <stripes:param name="page.spaceId" value="${actionBean.currentPage.space.id}"/>
                                </stripes:url>
                                document.location.href = '${url}';
                            }
                            else if ('1' == oMenuItem.value) { // edit this page's space
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.EditSpaceActionBean" event="view">
                                    <stripes:param name="space" value="${actionBean.currentPage.space.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('2' == oMenuItem.value) { // show this page's space as wiki page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.SpaceActionBean" event="view">
                                    <stripes:param name="space" value="${actionBean.currentPage.space.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('3' == oMenuItem.value) {  // delete this space
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.RemoveSpaceActionBean" event="remove">
                                    <stripes:param name="space" value="${actionBean.currentPage.space.id}"/>
                                </stripes:url>
                                document.location.href = '${url}';
                            }
                            else if ('4' == oMenuItem.value) { // show as wiki page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.PageActionBean" event="view">
                                    <stripes:param name="page" value="${actionBean.currentPage.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('5' == oMenuItem.value) { // delete this page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.RemovePageActionBean" event="remove_backToEditSpace">
                                    <stripes:param name="page" value="${actionBean.currentPage.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('6' == oMenuItem.value) { // add resource
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.resource.AddResourceActionBean" event="view">
                                    <stripes:param name="page" value="${actionBean.currentPage.id}"/>
                                    <stripes:param name="resource" value=""/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('7' == oMenuItem.value) { // mark as default page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.MarkPageAsSpaceDefaultActionBean" event="save_backToEditPage">
                                    <stripes:param name="page" value="${actionBean.currentPage.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('8' == oMenuItem.value) { // atom 1.0
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.general.PageFeedsActionBean" event="view">
                                    <stripes:param name="page" value="${actionBean.currentPage.id}"/>
                                    <stripes:param name="feedType" value="atom_1_0" />
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('9' == oMenuItem.value) { // rss 2.0
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.general.PageFeedsActionBean" event="view">
                                    <stripes:param name="page" value="${actionBean.currentPage.id}"/>
                                    <stripes:param name="feedType" value="rss_2_0" />
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else {
                                alert('unrecognized menu option');
                            }
                        }
                    };
                    //	Add a "click" event listener for the Button's Menu
                    manageHeaderMenu.getMenu().subscribe("click", onMenuClick);
                });
        </script>


        <!-- tabs -->
        <script type="text/javascript">
                    YAHOO.util.Event.onContentReady("tabPanel", function() {
                        var myTabs = new YAHOO.widget.TabView("tabPanel");
                        var tab0 = myTabs.getTab(0); // view
                        var tab1 = myTabs.getTab(1); // edit

                        tab0.on('click', function(e){ // when 'view' tab is clicked
                            <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.ViewPageActionBean" event="view">
                                <stripes:param name="currentPage" value="${actionBean.currentPage.id}" />   
                            </stripes:url>
                            document.location.href='${url}';
                        });
                        tab1.on('click', function(e){ // when 'edit' tab is clicked
                            <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.EditPageActionBean" event="view">
                                <stripes:param name="currentPage" value="${actionBean.currentPage.id}" />
                            </stripes:url>
                            document.location.href='${url}';
                        });
                    });
        </script>
    </stripes:layout-component>



    <stripes:layout-component name="_topNav">
        <H1>Edit Page [${actionBean.currentPage.name}]</H1>
        <UL class="gc-topnav-tabs">
            <LI>&nbsp;
                <span id="pageHeaderMenu">
                <input type="button" id="pageHeaderMenuButton" value="Options"/>
                <select id="pageHeaderMenuButtonSelect">
                    <jsecurity:hasPermission name="space:addPage:${actionBean.currentPage.space.id}">
                        <option value="0">Add Page</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:editSpace:${actionBean.currentPage.space.id}">
                        <option value="1">Edit This Page's Space</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:viewSpaceAsWiki:${actionBean.currentPage.space.id}">
                        <option value="2">Show This Page's Space As Wiki Page</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:removeSpace:${actionBean.currentPage.space.id}">
                        <option value="3">Delete This Space</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:viewPageAsWiki:${actionBean.currentPage.space.id}">
                        <option value="4">Show As Wiki Page</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:removePage:${actionBean.currentPage.space.id}">
                        <option value="5">Delete This Page</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:editPage:${actionBean.currentPage.space.id}">
                        <option value="6">Add Resource To Page</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:editSpace:${actionBean.currentPage.space.id}">
                        <option value="7">Mark As Default Page</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:viewSpace:${actionBean.currentPage.space.id}">
                        <option value="8">ATOM 1.0</option>
                        <option value="x">&nbsp;</option>
                        <option value="9">RSS 2.0</option>
                    </jsecurity:hasPermission>
                </select>
                </span>
            </LI>
        </UL>
    </stripes:layout-component>


    <stripes:layout-component name="_content">

        <stripes:messages/>

        <h2>Description [<a id="_hideDescription" href="#">Hide</a>/<a id="_showDescription" href="#">Show</a>]</h2>
        <div id="_description">
        <p>
            This is where the page details could be edited :-
            <ul>
                <li>Name - The name of this page (could contain only alphanumeric and '_' character)</li>
                <li>Description - The description of this page</li>
                <li>Space - The Space name of which this page belongs to</li>
                <li>Creator - The creator of this page</li>
                <li>Creation Date - The date this page was created</li>
                <li>Modifier - The last user that modified this page details</li>
                <li>Modification Date - The date this page was last modified</li>
                <li>Page Location - The template this page will be rendered based upon. This option normally would be
                    best left as it is unless you know what you are doing. :)</li>
                <li>Resource - The resource that's available in this page. Resources (eg. images etc) could be
                    referenced in a page through Wiki Markups. View this page as wiki page through the "Options"
                    dropdown menu and go to the tab "Wiki Syntax" for a list of possible wiki syntax (which includes
                    how to show a resource in a page)</li>
            </ul>
        </p>
        <p/>
        <p/>
        </div>


        <h2>Details</h2>
        <!-- tab panel -->
        <div id="tabPanel" class="yui-navset">
            <ul class="yui-nav">
                <li><a href="#tab1"><em>View</em></a></li>
                <li class="selected"><a href="#tab2"><em>Edit</em></a></li>
            </ul>
            <div class="yui-content">
                <div>&nbsp;Loading ...</div>
                <div>
                    <jsecurity:hasPermission name="space:editPage:${actionBean.currentPage.space.id}">
                                        <stripes:useActionBean
                                                var="themes"
                                                alwaysExecuteEvent="true"
                                                executeResolution="false"
                                                validate="false"
                                                beanclass="foo.bar.wiki.web.action.general.UtilitiesActionBean"
                                                event="themes" />
                                        <stripes:errors/>
                                        <p/>
                                        <p/>

                                        <h2>Page Details</h2>
                                        <stripes:form beanclass="foo.bar.wiki.web.action.page.EditPageActionBean" method="POST">
                                        <table width="100%">
                                            <stripes:hidden name="currentPage" value="${actionBean.currentPage.id}"/>
                                            <tr>
                                                <td>Name</td>
                                                <td>${actionBean.currentPage.name}</td>
                                            </tr>
                                            <tr>
                                                <td>Description</td>
                                                <td><stripes:textarea name="currentPage.description" value="${actionBean.currentPage.description}" style="width:100%; height:100%;"/></td>
                                            </tr>
                                            <tr>
                                                <td>Space</td>
                                                <td>${actionBean.currentPage.space.name}</td>
                                            </tr>
                                            <tr>
                                                <td>Creator</td>
                                                <td>${actionBean.currentPage.creator.username}</td>
                                            </tr>
                                            <tr>
                                                <td>Creation Date</td>
                                                <td><fmt:formatDate value="${actionBean.currentPage.creationDate}" pattern="dd/MM/yyyy hh:mm:ss a"/></td>
                                            </tr>
                                            <tr>
                                                <td>Modifier</td>
                                                <td>${actionBean.currentPage.modifier.username}</td>
                                            </tr>
                                            <tr>
                                                <td>Modification Date</td>
                                                <td><fmt:formatDate value="${actionBean.currentPage.modificationDate}" pattern="dd/MM/yyyy hh:mm:ss a"/></td>
                                            </tr>
                                            <tr>
                                                <td>Page Location</td>
                                                <td><stripes:text name="currentPage.pageLocation" value="${actionBean.currentPage.pageLocation}" /></td>
                                            </tr>
                                            <tr>
                                                <td colspan="2"><stripes:submit name="save">Save</stripes:submit></td>
                                            </tr>
                                        </table>
                                        </stripes:form>
                                        <p/>
                                        <p/>
                                        <p/>

                                        <h2>Resources</h2>
                                        <displaytag:table id="element" name="actionBean.currentPage.resources"
                                                      style="width:100%;"
                                                      excludedParams="*"
                                                      defaultsort="1"
                                                      defaultorder="ascending"
                                                      requestURI=""
                                                      requestURIcontext="true">
                                            <displaytag_el:column property="name" sortable="false" sortName="name" title="Name" />
                                            <displaytag_el:column property="mimeType" sortable="false" sortName="description" title="Description" />
                                            <displaytag_el:column property="creator.username" sortable="false" sortName="creator" title="Creator"/>
                                            <displaytag_el:column property="creationDate" sortable="false" sortName="creationDate" title="Creation Date"/>
                                            <displaytag_el:column property="modifier.username" sortable="false" sortName="modifier" title="Modifier"/>
                                            <displaytag_el:column property="modificationDate" sortable="false" sortName="modificationDate" title="Modification Date" />
                                            <displaytag_el:column title="Actions">
                                                <stripes:link beanclass="foo.bar.wiki.web.action.resource.EditResourceActionBean" event="view">
                                                    <stripes:param name="resource" value="${element.id}" />
                                                    Edit
                                                </stripes:link>|
                                                <stripes:link beanclass="foo.bar.wiki.web.action.resource.RemoveResourceActionBean" event="remove_backToEditPage">
                                                    <stripes:param name="resource" value="${element.id}" />
                                                    Delete
                                                </stripes:link>
                                            </displaytag_el:column>
                                        </displaytag:table>

                                        <p/>
                                        <p/>
                                        <p/>
                    </jsecurity:hasPermission>
                    <jsecurity:lacksPermission name="space:editPage:${actionBean.currentPage.space.id}">
                        Lacks "space:editPage:${actionBean.currentPage.space.id}" permission   
                    </jsecurity:lacksPermission>
                </div>
             </div>
        </div>
    </stripes:layout-component>

</stripes:layout-render>


